#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mywindows.h"
#include "disp.h"
#include "data.h"
#include "control.h"

int main()
{
    //1.初始化
    initWindows();

    dataInitData();

    dispInitGame();

    //输出蛇和食物
    dispDrawSnake(&snake);
    dispDrawFood(&food);

    char ch;
    DIR d;
    while(1){
        ch = getch();
        if(ch == 'd') {
            d = RIGHT;
        }else if(ch == 'a') {
            d = LEFT;
        }else if(ch == 'w') {
            d = UP;
        }else if(ch == 's') {
            d = DOWN;
        }else if(ch == 'q') {
            dispDrawOverInfo(score);
            break;
        }else {
            continue;
        }
        //dataSnakeMove(d);
        ReType r = dataMoveSnake2(d);
        if(r == DirError) {
            continue;
        }else if(r == Hit) {
            dispDrawOverInfo(score);
            //dataInitData();
            break;
        }else{
            //下面包含3种情况: 仅移动  得分  等级增加
            dispDrawSnake(&snake);
            if(r == Move)
                continue;

            dataUpdateFood();
            dispDrawScore(score);
            dispDrawFood(&food);
            if(r == Grade){
                dispDrawGrade(grade);
            }
        }
    }
}
